package com.thread;

/**
 * Created by Sunny on 2016/4/4.
 */
public class RunnableTest1 implements  Runnable {
    private String name ;

    public void run() {
        System.out.println(name+"Runnable运行");
    }

    public RunnableTest1(String name) {
        this.name = name;
    }

    /**
     * 但是在使用Runnable定义的子类中没有start()方法，只有Thread类中才有。此时观察Thread类，
     * 有一个构造方法：public Thread(Runnable targer)此构造方法接受Runnable的子类实例，也就是说可以通过Thread类来启动Runnable实现的多线程。（start()可以协调系统的资源）:
     * @param args
     */
    public static void main(String[] args) {
        RunnableTest1 test1 = new RunnableTest1("线程1");
        RunnableTest1 test2 = new RunnableTest1("线程2");
/*        test1.run();
        test2.run();*/
        Thread thread =   new Thread(test1);
        thread.start();
        thread.start();
       // new Thread(test2).start();
         /* new Thread(test1).run();
        new Thread(test2).run();*/
    }
}
